package gipf.trunk;
import java.util.ArrayList;

/**
 * @author eric
 *has an adjMatrix of true and false, saying if one position is connected with another
 *also has an positions[][] matrix which has empt spots, but also contains all positions (1|1 to 9|5) 
 */
public class staticBoard {
	static boolean[][] adjMatrix = new boolean[61][61];
	static position[][] board = new position[17][17];
	static int[] outterPieces = {0, 1, 2, 3,4 ,10, 17, 25, 34, 42, 49, 55, 60, 59, 58, 57, 56, 50, 43, 35, 26, 18, 11, 5};
	static int[] innerPieces = {6, 7, 8, 9, 16, 24, 33, 41, 48, 54, 53, 52, 51, 44, 36, 27, 19, 12};


	/**
	 * create a staticboard, this should only be done once, it is
	 * used for statements about pieces, such as full lines and adjacency.
	 * it has a adjMatrix[][] which is not used that often and a board[][].
	 * the latter contains positions, which store the corrsponding position on the board (e.g. 5|5)
	 * their corresponding index in the pieces[] of State (e.g. 30) and their coordinate in the GUI
	 */
	public staticBoard() {
		init();
	}

	/**
	 * @param a ,starting position for the full-line-check 
	 * @param b ,second position for the line check, using the two positions, a direction is determined
	 * @param pieces the current list of pieces placed
	 * @return false if there is an empty spot in the current line, true if the line is full
	 */
	public static boolean lineFull(position a, position b, int[] pieces) {

		int[] direction = determineVector(a.getBoardIndex(), b.getBoardIndex());

		ArrayList<Integer> checkPieces = new ArrayList<Integer>();

		checkPieces.add(b.getIndex());
		int[] next = new int[2];
		next[0] = b.getBoardIndex()[0] + direction[0];
		next[1] = b.getBoardIndex()[1] + direction[1];

		checkPieces.add(board[next[0]][next[1]].getIndex());

		while (next[0] >= 2 && next[0] <= 14 && next[1] >= 2 && next[1] <= 14) {
			next[0] += direction[0];
			next[1] += direction[1];
			
			int index = board[next[0]][next[1]].getIndex();
			
			if (index != 61 && !outter(index))
				checkPieces.add(index);
		}
		
		for (int i = 0; i < checkPieces.size(); i++) {
			if (pieces[checkPieces.get(i)] == 0)
				return false;
		}

		return true;

	}
	
	/**
	 * @param index of the position which is checked
	 * @return true, if the given position is on the second "ring"
	 */
	public static boolean inner(int index) {
		for (int i = 0; i < innerPieces.length; i++ ){
			if (index == innerPieces[i])
				return true;
		}
		
		return false;
	}
	
	/**
	 * @param index of the position which is checked
	 * @return true, if the given position is on the outter "ring"
	 */
	public static boolean outter(int index) {
		for (int i = 0; i < outterPieces.length; i++ ){
			if (index == outterPieces[i])
				return true;
		}
		
		return false;
	}

	/**
	 * @param boardState the current boardState, which contains the int[] of pieces
	 * @param direction the direction of the last move, for finding all possible ways of
	 * having created a line of four somewhere.
	 * @return an arraylist of arraylists which contain integers in which there is at least a line of four
	 */
	public static ArrayList<ArrayList<Integer>> finishedLines(State boardState,
			int direction) {
		direction = (direction) % 3;

		ArrayList<ArrayList<position>> alignedPositions = new ArrayList<ArrayList<position>>();
		ArrayList<position> completedLines = boardState.getLastMoves();

		alignedPositions.add(wholeLineIndexList(completedLines.get(0),
				direction));

		for (position piece : completedLines) {
			switch (direction) {
			case 0:
				for (int direction2 = 1; direction2 < 3; direction2++) {
					alignedPositions.add(wholeLineIndexList(piece, direction2));
				}
				break;
			case 1:
				alignedPositions.add(wholeLineIndexList(piece, 2));
				alignedPositions.add(wholeLineIndexList(piece, 0));
				break;
			case 2:
				for (int direction2 = 0; direction2 < 2; direction2++) {
					alignedPositions.add(wholeLineIndexList(piece, direction2));
				}
				break;
			default:
				break;
			}
		}

		boolean fourTogether = false;
		boolean broken = false;

		ArrayList<ArrayList<Integer>> lists = new ArrayList<ArrayList<Integer>>();

		for (ArrayList<position> positions : alignedPositions) {
			fourTogether = false;
			broken = false;

			ArrayList<Integer> connected = new ArrayList<Integer>();

			int player1Count = 0;
			int player2Count = 0;

			for (position currentPosition : positions) {
				int nodeIndex = currentPosition.getIndex();

				int alignedPiece = boardState.getPieces()[nodeIndex];

				if (alignedPiece == 0) {
					if (!fourTogether) {
						connected.clear();
					} else
						broken = true;
					player1Count = 0;
					player2Count = 0;
				} else {
					if (alignedPiece == 1) {
						if (!broken)
							connected.add(nodeIndex);
						player1Count++;
						player2Count = 0;

					}
					if (alignedPiece == 2) {
						if (!broken)
							connected.add(nodeIndex);
						player2Count++;
						player1Count = 0;
					}
				}
				if (player1Count >= 4 || player2Count >= 4) {
					fourTogether = true;
				}
			}
			if (fourTogether && !lists.contains(connected)) {
				lists.add(connected);
			}

		}
		return lists;
	}

	/**
	 * @param position from where you want to check for the indexes of a whole line
	 * @param direction the direction of the line, which indexes you want to have
	 * @return all positions which are to be checked to determine a while line
	 */
	private static ArrayList<position> wholeLineIndexList(position position,
			int direction) {
		// to be done
		ArrayList<position> list = new ArrayList<position>();
		list.add(position);

		
		try {
			position next1 = getAdjecent(position, direction);

			while(next1.getIndex() != 61) {
				list.add(next1);
				position = next1;
				next1 = getAdjecent(position, direction);
			} 

		} catch (Exception e) {
		}

		try {
			position next2 = getAdjecent(position, ((direction + 3) % 6));

			
			while(next2.getIndex() != 61) {
				list.add(next2);
				position = next2;
				next2 = getAdjecent(position, ((direction + 3) % 6));
			} 

		} catch (Exception e2) {
		}

		return list;
	}

	/**
	 * @param index1 given an index in the board[][] of a first position and
	 * @param index2 an index of the second position from the board[][]
	 * @return the vector the two boardindexes form in the board[][]
	 */
	private static int[] determineVector(int[] index1, int[] index2) {

		int deltaX = index2[0] - index1[0];
		int deltaY = index2[1] - index1[1];

		int[] toBeReturned = new int[2];
		toBeReturned[0] = deltaX;
		toBeReturned[1] = deltaY;

		return toBeReturned;
	}

	/**
	 * @param a ,position to go to
	 * @param b ,the other position to go to
	 * @return the int describing the direction from position a to position b (0 - 5)
	 */
	public static int determineDirection(position a, position b) {
		int deltaX = b.getBoardIndex()[0] - a.getBoardIndex()[0];
		int deltaY = b.getBoardIndex()[1] - a.getBoardIndex()[1];

		if (deltaX == 0) {
			if (deltaY == 2)
				return 3;
			else if (deltaY == -2)
				return 0;
		} else if (deltaX == -2) {
			if (deltaY == -1)
				return 5;
			else if (deltaY == 1)
				return 4;
		} else if (deltaX == 2) {
			if (deltaY == -1)
				return 1;
			else if (deltaY == 1)
				return 2;
		}

		return 6;
	}

	/**
	 * @return all posiible positions in the board on which a piece can be placed
	 */
	public static ArrayList<position> getPositionList() {
		ArrayList<position> positions = new ArrayList<position>();

		for (int x = 0; x < board.length; x++) {
			for (int y = 0; y < board[x].length; y++) {
				if (board[x][y].getIndex() != 61)
					positions.add(board[x][y]);
			}
		}

		return positions;
	}

	/**
	 * @param a ,position from where you want to get a adjecent position
	 * @param direction ,direction in that you want to get the adjecent position
	 * @return adjecent position, given a certain direction
	 */
	public static position getAdjecent(position a, int direction) {
		int[] vector = new int[2];

		switch (direction) {
		case 0:
			vector[0] = 0;
			vector[1] = -2;
			break;
		case 1:
			vector[0] = 2;
			vector[1] = -1;
			break;
		case 2:
			vector[0] = 2;
			vector[1] = 1;
			break;
		case 3:
			vector[0] = 0;
			vector[1] = 2;
			break;
		case 4:
			vector[0] = -2;
			vector[1] = 1;
			break;
		case 5:
			vector[0] = -2;
			vector[1] = -1;
			break;
		}

		return board[a.getBoardIndex()[0] + vector[0]][a.getBoardIndex()[1]
				+ vector[1]];
	}

	/**
	 * @param posA2
	 * @param posB2
	 * @return true, if two positions are adjacent
	 */
	public boolean areAdjacent(position posA2, position posB2) {
		int posA = translatePosition(posA2);
		int posB = translatePosition(posB2);
		if (posA != 61 && posB != 61)
			return adjMatrix[posA][posB];
		return false;
	}

	/**
	 * @param position
	 * @return return a list of indexes of adjecent positions
	 */
	public ArrayList<Integer> adjFields(position position) {
		ArrayList<Integer> adj = new ArrayList<Integer>();
		int pos = translatePosition(position);

		for (int i = 0; i < adjMatrix[pos].length; i++) {
			if (adjMatrix[pos][i])
				adj.add(i);
		}

		return adj;

	}

	/**
	 * @param position
	 * @return return all adjacent positions, not only the indexes
	 */
	public static ArrayList<position> adjFieldsPosition(position position) {
		ArrayList<position> adj = new ArrayList<position>();
		int pos = translatePosition(position);

		for (int i = 0; i < adjMatrix[pos].length; i++) {
			if (adjMatrix[pos][i]) {
				adj.add(getPosition(i));
			}
		}

		return adj;

	}

	/**
	 * @param index
	 * @return get the position which has the given index
	 */
	public static position getPosition(int index) {
		for (int x = 0; x < board.length; x++) {
			for (int y = 0; y < board[x].length; y++) {
				if (board[x][y].getIndex() == index)
					return board[x][y];
			}
		}
		return null;
	}

	/**
	 * @return print the adjecency matrix
	 */
	public String printAdj() {
		String toBeReturned = "";

		for (int x = 0; x < adjMatrix.length; x++) {
			for (int y = 0; y < adjMatrix[x].length; y++) {
				if (adjMatrix[y][x])
					toBeReturned += "#";
				else
					toBeReturned += " ";
			}
			toBeReturned += "\n";
		}

		return toBeReturned;
	}

	/**
	 * @param index
	 * @return return the board coordinate (e.g. 5|5) of a index (e.g. 30)
	 */
	public static position translateIndex(int index) {
		int[] position = new int[2];

		if (index >= 0 && index <= 4) {
			position[0] = 1;
			switch (index) {
			case 0:
				position[1] = 1;
				break;
			case 1:
				position[1] = 2;
				break;
			case 2:
				position[1] = 3;
				break;
			case 3:
				position[1] = 4;
				break;
			case 4:
				position[1] = 5;
				break;
			}
		} else if (index >= 5 && index <= 10) {
			position[0] = 2;
			switch (index) {
			case 5:
				position[1] = 1;
				break;
			case 6:
				position[1] = 2;
				break;
			case 7:
				position[1] = 3;
				break;
			case 8:
				position[1] = 4;
				break;
			case 9:
				position[1] = 5;
				break;
			case 10:
				position[1] = 6;
				break;

			}
		} else if (index >= 11 && index <= 17) {
			position[0] = 3;
			switch (index) {
			case 11:
				position[1] = 1;
				break;
			case 12:
				position[1] = 2;
				break;
			case 13:
				position[1] = 3;
				break;
			case 14:
				position[1] = 4;
				break;
			case 15:
				position[1] = 5;
				break;
			case 16:
				position[1] = 6;
				break;
			case 17:
				position[1] = 7;
				break;
			}
		} else if (index >= 18 && index <= 25) {
			position[0] = 4;
			switch (index) {
			case 18:
				position[1] = 1;
				break;
			case 19:
				position[1] = 2;
				break;
			case 20:
				position[1] = 3;
				break;
			case 21:
				position[1] = 4;
				break;
			case 22:
				position[1] = 5;
				break;
			case 23:
				position[1] = 6;
				break;
			case 24:
				position[1] = 7;
				break;
			case 25:
				position[1] = 8;
				break;
			}
		} else if (index >= 26 && index <= 34) {
			position[0] = 5;
			switch (index) {
			case 26:
				position[1] = 1;
				break;
			case 27:
				position[1] = 2;
				break;
			case 28:
				position[1] = 3;
				break;
			case 29:
				position[1] = 4;
				break;
			case 30:
				position[1] = 5;
				break;
			case 31:
				position[1] = 6;
				break;
			case 32:
				position[1] = 7;
				break;
			case 33:
				position[1] = 8;
				break;
			case 34:
				position[1] = 9;
				break;
			}
		} else if (index >= 35 && index <= 42) {
			position[0] = 6;
			switch (index) {
			case 35:
				position[1] = 1;
				break;
			case 36:
				position[1] = 2;
				break;
			case 37:
				position[1] = 3;
				break;
			case 38:
				position[1] = 4;
				break;
			case 39:
				position[1] = 5;
				break;
			case 40:
				position[1] = 6;
				break;
			case 41:
				position[1] = 7;
				break;
			case 42:
				position[1] = 8;
				break;
			}
		} else if (index >= 43 && index <= 49) {
			position[0] = 7;
			switch (index) {
			case 43:
				position[1] = 1;
				break;
			case 44:
				position[1] = 2;
				break;
			case 45:
				position[1] = 3;
				break;
			case 46:
				position[1] = 4;
				break;
			case 47:
				position[1] = 5;
				break;
			case 48:
				position[1] = 6;
				break;
			case 49:
				position[1] = 7;
				break;
			}
		} else if (index >= 50 && index <= 55) {
			position[0] = 8;
			switch (index) {
			case 50:
				position[1] = 1;
				break;
			case 51:
				position[1] = 2;
				break;
			case 52:
				position[1] = 3;
				break;
			case 53:
				position[1] = 4;
				break;
			case 54:
				position[1] = 5;
				break;
			case 55:
				position[1] = 6;
				break;

			}
		} else if (index >= 56 && index <= 60) {
			position[0] = 9;
			switch (index) {
			case 56:
				position[1] = 1;
				break;
			case 57:
				position[1] = 2;
				break;
			case 58:
				position[1] = 3;
				break;
			case 59:
				position[1] = 4;
				break;
			case 60:
				position[1] = 5;
				break;
			}
		}
		position positionObject = new position(position[0], position[1]);
		return positionObject;
	}

	/**
	 * @param position
	 * @return the index value (e.g. 30) of of a given position (5|5)
	 */
	public static int translatePosition(position position) {
		int x = position.coordinate()[0];
		int y = position.coordinate()[1];

		switch (x) {
		case 1:
			switch (y) {
			case 1:
				return 0;
			case 2:
				return 1;
			case 3:
				return 2;
			case 4:
				return 3;
			case 5:
				return 4;
			}
		case 2:
			switch (y) {
			case 1:
				return 5;
			case 2:
				return 6;
			case 3:
				return 7;
			case 4:
				return 8;
			case 5:
				return 9;
			case 6:
				return 10;
			}
		case 3:
			switch (y) {
			case 1:
				return 11;
			case 2:
				return 12;
			case 3:
				return 13;
			case 4:
				return 14;
			case 5:
				return 15;
			case 6:
				return 16;
			case 7:
				return 17;
			}
		case 4:
			switch (y) {
			case 1:
				return 18;
			case 2:
				return 19;
			case 3:
				return 20;
			case 4:
				return 21;
			case 5:
				return 22;
			case 6:
				return 23;
			case 7:
				return 24;
			case 8:
				return 25;
			}
		case 5:
			switch (y) {
			case 1:
				return 26;
			case 2:
				return 27;
			case 3:
				return 28;
			case 4:
				return 29;
			case 5:
				return 30;
			case 6:
				return 31;
			case 7:
				return 32;
			case 8:
				return 33;
			case 9:
				return 34;
			}
		case 6:
			switch (y) {
			case 1:
				return 35;
			case 2:
				return 36;
			case 3:
				return 37;
			case 4:
				return 38;
			case 5:
				return 39;
			case 6:
				return 40;
			case 7:
				return 41;
			case 8:
				return 42;
			}
		case 7:
			switch (y) {
			case 1:
				return 43;
			case 2:
				return 44;
			case 3:
				return 45;
			case 4:
				return 46;
			case 5:
				return 47;
			case 6:
				return 48;
			case 7:
				return 49;
			}
		case 8:
			switch (y) {
			case 1:
				return 50;
			case 2:
				return 51;
			case 3:
				return 52;
			case 4:
				return 53;
			case 5:
				return 54;
			case 6:
				return 55;
			}
		case 9:
			switch (y) {
			case 1:
				return 56;
			case 2:
				return 57;
			case 3:
				return 58;
			case 4:
				return 59;
			case 5:
				return 60;
			}
		default:
			return 61;
		}
	}

	/**
	 * initialize the adjacency matrix (not used much) and the board[][] of positions
	 */
	private void init() {
		for (int x = 0; x < adjMatrix.length; x++) {
			for (int y = 0; y < adjMatrix[x].length; y++) {
				adjMatrix[x][y] = false;
				switch (x) {
				case 0:
					if (y == 6)
						adjMatrix[x][y] = true;
					break;
				case 1:
					if (y == 6 || y == 7)
						adjMatrix[x][y] = true;
					break;
				case 2:
					if (y == 7 || y == 8)
						adjMatrix[x][y] = true;
					break;
				case 3:
					if (y == 8 || y == 9)
						adjMatrix[x][y] = true;
					break;
				case 4:
					if (y == 9)
						adjMatrix[x][y] = true;
					break;
				case 5:
					if (y == 6 || y == 12)
						adjMatrix[x][y] = true;
					break;
				case 6:
					if (y == 7 || y == 12 || y == 13)
						adjMatrix[x][y] = true;
					break;
				case 7:
					if (y == 6 || y == 8 || y == 13 || y == 14)
						adjMatrix[x][y] = true;
					break;
				case 8:
					if (y == 7 || y == 9 || y == 14 || y == 15)
						adjMatrix[x][y] = true;
					break;
				case 9:
					if (y == 8 || y == 15 || y == 16)
						adjMatrix[x][y] = true;
					break;
				case 10:
					if (y == 9 || y == 16)
						adjMatrix[x][y] = true;
					break;
				case 11:
					if (y == 12 || y == 19)
						adjMatrix[x][y] = true;
					break;
				case 12:
					if (y == 6 || y == 13 || y == 19 || y == 20)
						adjMatrix[x][y] = true;
					break;
				case 13:
					if (y == 6 || y == 7 || y == 12 || y == 14 || y == 20
							|| y == 21)
						adjMatrix[x][y] = true;
					break;
				case 14:
					if (y == 7 || y == 8 || y == 13 || y == 15 || y == 21
							|| y == 22)
						adjMatrix[x][y] = true;
					break;
				case 15:
					if (y == 8 || y == 9 || y == 14 || y == 16 || y == 22
							|| y == 23)
						adjMatrix[x][y] = true;
					break;
				case 16:
					if (y == 9 || y == 15 || y == 23 || y == 24)
						adjMatrix[x][y] = true;
					break;
				case 17:
					if (y == 16 || y == 24)
						adjMatrix[x][y] = true;
					break;
				case 18:
					if (y == 19 || y == 27)
						adjMatrix[x][y] = true;
					break;
				case 19:
					if (y == 12 || y == 20 || y == 27 || y == 28)
						adjMatrix[x][y] = true;
					break;
				case 20:
					if (y == 12 || y == 13 || y == 19 || y == 21 || y == 28
							|| y == 29)
						adjMatrix[x][y] = true;
					break;
				case 21:
					if (y == 13 || y == 14 || y == 20 || y == 22 || y == 29
							|| y == 30)
						adjMatrix[x][y] = true;
					break;
				case 22:
					if (y == 14 || y == 15 || y == 21 || y == 23 || y == 30
							|| y == 31)
						adjMatrix[x][y] = true;
					break;
				case 23:
					if (y == 15 || y == 16 || y == 22 || y == 24 || y == 31
							|| y == 32)
						adjMatrix[x][y] = true;
					break;
				case 24:
					if (y == 16 || y == 23 || y == 32 || y == 33)
						adjMatrix[x][y] = true;
					break;
				case 25:
					if (y == 24 || y == 33)
						adjMatrix[x][y] = true;
					break;
				case 26:
					if (y == 27)
						adjMatrix[x][y] = true;
					break;
				case 27:
					if (y == 19 || y == 28 || y == 36)
						adjMatrix[x][y] = true;
					break;
				case 28:
					if (y == 19 || y == 20 || y == 27 || y == 29 || y == 36
							|| y == 37)
						adjMatrix[x][y] = true;
					break;
				case 29:
					if (y == 20 || y == 21 || y == 28 || y == 30 || y == 37
							|| y == 38)
						adjMatrix[x][y] = true;
					break;
				case 30:
					if (y == 21 || y == 22 || y == 29 || y == 31 || y == 38
							|| y == 39)
						adjMatrix[x][y] = true;
					break;
				case 31:
					if (y == 22 || y == 23 || y == 30 || y == 32 || y == 39
							|| y == 40)
						adjMatrix[x][y] = true;
					break;
				case 32:
					if (y == 23 || y == 24 || y == 31 || y == 33 || y == 40
							|| y == 41)
						adjMatrix[x][y] = true;
					break;
				case 33:
					if (y == 24 || y == 32 || y == 41)
						adjMatrix[x][y] = true;
					break;
				case 34:
					if (y == 33)
						adjMatrix[x][y] = true;
					break;
				case 35:
					if (y == 27 || y == 36)
						adjMatrix[x][y] = true;
					break;
				case 36:
					if (y == 27 || y == 28 || y == 37 || y == 44)
						adjMatrix[x][y] = true;
					break;
				case 37:
					if (y == 28 || y == 29 || y == 36 || y == 38 || y == 44
							|| y == 45)
						adjMatrix[x][y] = true;
					break;
				case 38:
					if (y == 29 || y == 30 || y == 37 || y == 39 || y == 45
							|| y == 46)
						adjMatrix[x][y] = true;
					break;
				case 39:
					if (y == 30 || y == 31 || y == 38 || y == 40 || y == 46
							|| y == 47)
						adjMatrix[x][y] = true;
					break;
				case 40:
					if (y == 31 || y == 32 || y == 39 || y == 41 || y == 47
							|| y == 48)
						adjMatrix[x][y] = true;
					break;
				case 41:
					if (y == 32 || y == 33 || y == 40 || y == 48)
						adjMatrix[x][y] = true;
					break;
				case 42:
					if (y == 33 || y == 41)
						adjMatrix[x][y] = true;
					break;
				case 43:
					if (y == 36 || y == 44)
						adjMatrix[x][y] = true;
					break;
				case 44:
					if (y == 36 || y == 37 || y == 45 || y == 51)
						adjMatrix[x][y] = true;
					break;
				case 45:
					if (y == 37 || y == 38 || y == 44 || y == 46 || y == 51
							|| y == 52)
						adjMatrix[x][y] = true;
					break;
				case 46:
					if (y == 38 || y == 39 || y == 45 || y == 47 || y == 52
							|| y == 53)
						adjMatrix[x][y] = true;
					break;
				case 47:
					if (y == 39 || y == 40 || y == 46 || y == 48 || y == 53
							|| y == 54)
						adjMatrix[x][y] = true;
					break;
				case 48:
					if (y == 40 || y == 41 || y == 47 || y == 54)
						adjMatrix[x][y] = true;
					break;
				case 49:
					if (y == 41 || y == 48)
						adjMatrix[x][y] = true;
					break;
				case 50:
					if (y == 44 || y == 51)
						adjMatrix[x][y] = true;
					break;
				case 51:
					if (y == 44 || y == 45 || y == 52)
						adjMatrix[x][y] = true;
					break;
				case 52:
					if (y == 45 || y == 46 || y == 51 || y == 53)
						adjMatrix[x][y] = true;
					break;
				case 53:
					if (y == 46 || y == 47 || y == 52 || y == 54)
						adjMatrix[x][y] = true;
					break;
				case 54:
					if (y == 47 || y == 48 || y == 53)
						adjMatrix[x][y] = true;
					break;
				case 55:
					if (y == 48 || y == 54)
						adjMatrix[x][y] = true;
					break;
				case 56:
					if (y == 51)
						adjMatrix[x][y] = true;
					break;
				case 57:
					if (y == 51 || y == 52)
						adjMatrix[x][y] = true;
					break;
				case 58:
					if (y == 52 || y == 53)
						adjMatrix[x][y] = true;
					break;
				case 59:
					if (y == 53 || y == 54)
						adjMatrix[x][y] = true;
					break;
				case 60:
					if (y == 54)
						adjMatrix[x][y] = true;
					break;
				}
			}
		}

		for (int x = 0; x < board.length; x++) {
			for (int y = 0; y < board[x].length; y++) {
				board[x][y] = new position();

				switch (x) {
				case 0:
					if (y == 4) {
						board[x][y] = new position(1, 5);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 6) {
						board[x][y] = new position(1, 4);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 8) {
						board[x][y] = new position(1, 3);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 10) {
						board[x][y] = new position(1, 2);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 12) {
						board[x][y] = new position(1, 1);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					break;
				case 2:
					if (y == 3) {
						board[x][y] = new position(2, 6);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 5) {
						board[x][y] = new position(2, 5);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 7) {
						board[x][y] = new position(2, 4);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 9) {
						board[x][y] = new position(2, 3);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 11) {
						board[x][y] = new position(2, 2);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 13) {
						board[x][y] = new position(2, 1);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					break;
				case 4:
					if (y == 2) {
						board[x][y] = new position(3, 7);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 4) {
						board[x][y] = new position(3, 6);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 6) {
						board[x][y] = new position(3, 5);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 8) {
						board[x][y] = new position(3, 4);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 10) {
						board[x][y] = new position(3, 3);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 12) {
						board[x][y] = new position(3, 2);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 14) {
						board[x][y] = new position(3, 1);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					break;
				case 6:
					if (y == 1) {
						board[x][y] = new position(4, 8);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 3) {
						board[x][y] = new position(4, 7);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 5) {
						board[x][y] = new position(4, 6);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 7) {
						board[x][y] = new position(4, 5);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 9) {
						board[x][y] = new position(4, 4);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 11) {
						board[x][y] = new position(4, 3);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 13) {
						board[x][y] = new position(4, 2);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 15) {
						board[x][y] = new position(4, 1);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					break;
				case 8:
					if (y == 0) {
						board[x][y] = new position(5, 9);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 2) {
						board[x][y] = new position(5, 8);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 4) {
						board[x][y] = new position(5, 7);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 6) {
						board[x][y] = new position(5, 6);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 8) {
						board[x][y] = new position(5, 5);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 10) {
						board[x][y] = new position(5, 4);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 12) {
						board[x][y] = new position(5, 3);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 14) {
						board[x][y] = new position(5, 2);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 16) {
						board[x][y] = new position(5, 1);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					break;
				case 10:
					if (y == 1) {
						board[x][y] = new position(6, 8);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 3) {
						board[x][y] = new position(6, 7);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 5) {
						board[x][y] = new position(6, 6);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 7) {
						board[x][y] = new position(6, 5);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 9) {
						board[x][y] = new position(6, 4);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 11) {
						board[x][y] = new position(6, 3);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 13) {
						board[x][y] = new position(6, 2);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 15) {
						board[x][y] = new position(6, 1);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					break;
				case 12:
					if (y == 2) {
						board[x][y] = new position(7, 7);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 4) {
						board[x][y] = new position(7, 6);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 6) {
						board[x][y] = new position(7, 5);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 8) {
						board[x][y] = new position(7, 4);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 10) {
						board[x][y] = new position(7, 3);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 12) {
						board[x][y] = new position(7, 2);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 14) {
						board[x][y] = new position(7, 1);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					break;
				case 14:
					if (y == 3) {
						board[x][y] = new position(8, 6);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 5) {
						board[x][y] = new position(8, 5);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 7) {
						board[x][y] = new position(8, 4);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 9) {
						board[x][y] = new position(8, 3);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 11) {
						board[x][y] = new position(8, 2);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 13) {
						board[x][y] = new position(8, 1);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					break;
				case 16:
					if (y == 4) {
						board[x][y] = new position(9, 5);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 6) {
						board[x][y] = new position(9, 4);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 8) {
						board[x][y] = new position(9, 3);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 10) {
						board[x][y] = new position(9, 2);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					if (y == 12) {
						board[x][y] = new position(9, 1);
						board[x][y].setBoardIndex(x, y);
						break;
					}
					break;
				}
			}
		}

	}

}
